var _n45;
var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2Card = require("Card");
var $2PlantBase = require("PlantBase");
var $2kc = require("kc");
var $2PlantMgr = require("PlantMgr");
var $2ZombieMgr = require("ZombieMgr");
var $2DataManager = require("DataManager");
var $2BundleManager = require("BundleManager");
var $2MyUtils = require("MyUtils");
var $2GoldManager = require("GoldManager");
var $2UIManager = require("UIManager");
var $2Common = require("Common");
var $2UserDataManager = require("UserDataManager");
var $2AudioManager = require("AudioManager");
var $2KDefine = require("KDefine");
var $2Gold = require("Gold");
var $2Hts = require("Hts");
var $2ADManager = require("ADManager");
var $2TaSdk = require("TaSdk");
var $2Ball = require("Ball");
var $2Boss = require("Boss");
var $2PoolManager = require("PoolManager");
var $2Zombie = require("Zombie");
var $2TombStone = require("TombStone");
var $2GameManager = require("GameManager");
var $2pvzChannel = require("pvzChannel");
var $2pvzRecordVideoBt = require("pvzRecordVideoBt");
var $2SharePanelUI = require("SharePanelUI");
var $2SpIcon = require("SpIcon");
var $2AdReviveUI = require("AdReviveUI");
var $2AdBombUI = require("AdBombUI");
var $2NoSunUI = require("NoSunUI");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_SceneStage = _n45 = /* */function (_cc$Component63) {
  babel_inherits(n, _cc$Component63);
  var _super79 = babel_createSuper(n);
  function n() {
    var _this177;
    babel_classCallCheck(this, n);
    _this177 = _super79.apply(this, arguments);
    _this177.spIcon = null;
    _this177.video1 = null;
    _this177.video2 = null;
    _this177.video3 = null;
    _this177.video4 = null;
    _this177.groudNode = null;
    _this177.recordBt = null;
    _this177.cardPanel = null;
    _this177.plantPanel = null;
    _this177.goldNumLabel = null;
    _this177.shovel = null;
    _this177.gameProgress = null;
    _this177.autoBtn = null;
    _this177.sunParent = null;
    _this177.boss = null;
    _this177.selectCardID = 0;
    _this177.lastCardID = 0;
    _this177.bombNums = 0;
    _this177.allTime = 0;
    _this177.nowTime = 0;
    _this177.isPlay = false;
    _this177.isGuide = false;
    _this177.isRecord = false;
    _this177.cardSelectShadow = null;
    _this177.groudXMin = $2DataManager.default.instance.groudStartPo.x;
    _this177.groudXMax = $2DataManager.default.instance.groudStartPo.x + $2DataManager.default.instance.blockWidth * $2DataManager.default.instance.col;
    _this177.groudYMin = $2DataManager.default.instance.groudStartPo.y;
    _this177.groudYMax = $2DataManager.default.instance.groudStartPo.y + $2DataManager.default.instance.blockHeight * $2DataManager.default.instance.row;
    _this177.pickStartPo = null;
    _this177.cardNodeMap = new Map();
    _this177.plantNodeMap = new Map();
    _this177.shovelShadow = null;
    _this177.autoPick = false;
    _this177.tempPlant = null;
    _this177.ballPlantID = [];
    _this177.ballPlant = 0;
    _this177.canCreateBall = true;
    _this177.noCDTime = 0;
    _this177.lbs_btn = null;
    _this177.bs1 = null;
    _this177.bs2 = null;
    _this177.bs_btn = null;
    _this177.bs_bg = null;
    _this177.is_lbs = false;
    _this177.isPause = false;
    _this177.spIconType = 0;
    return _this177;
  }
  babel_createClass(n, [{
    key: "onLoad",
    value: function onLoad() {
      var _this178 = this;
      $2DataManager.default.instance.is_bowling = false;
      this.lbs_btn = cc.find("lbs_btn", this.node);
      this.bs1 = cc.find("lbs_btn/bs_bg/bs1", this.node);
      this.bs2 = cc.find("lbs_btn/bs_bg/bs2", this.node);
      this.bs_btn = cc.find("lbs_btn/bs_bg/bs_btn", this.node);
      this.bs_bg = cc.find("lbs_btn/bs_bg", this.node);
      this.bs_bg.on(cc.Node.EventType.TOUCH_START, this.on_lbs, this);
      this.bs_btn.setPosition(this.bs2.position);
      var e = $2BundleManager.default.instance.getBundleRes("Spine", "jiangshiboss/jiangshiboss", sp.SkeletonData);
      console.log("====BOSSS!!", e);
      cc.dynamicAtlasManager.reset();
      _n45._instance = this;
      $2DataManager.default.instance.initBlockPos();
      $2ZombieMgr.default.instance().init(this);
      this.autoPick = false;
      this.bombNums = 0;
      var t = cc.find("Canvas/Bg").width * cc.find("Canvas/Bg").scaleX / 2 - $2kc.default.view_x;
      if (20 != $2DataManager.default.instance.level) {
        $2AudioManager.default.instance.playMusic($2KDefine.AudioName.MainBgm, true);
      } else {
        $2TaSdk.default.instance.postEvent("System", {
          system: "Boss关"
        });
        $2AudioManager.default.instance.playMusic($2KDefine.AudioName.BossBgm, true);
        this.hpProgress = this.node.getChildByName("HpProgress");
        this.node.getChildByName("born").active = true;
        this.boss.node.active = true;
      }
      cc.find("Canvas/Bg").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/Bg2", cc.SpriteFrame);
      cc.find("Canvas/Bg").x = 81;
      $2GameManager.default.instance.changeOrientation();
      this.goldNumLabel.string = this.goldNums + "";
      this.shovelShadow = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "Object/shovel", cc.Prefab));
      this.shovelShadow.parent = this.groudNode;
      this.shovelShadow.opacity = 0;
      $2UIManager.default.instance.hideUI("MoneyPanelUI");
      $2TaSdk.default.instance.postEvent("in_level", {
        level: $2DataManager.default.instance.level
      });
      this.ballPlant = 0;
      this.node.getChildByName("PauseBtn").active = false;
      cc.tween(cc.find("Canvas/Main Camera")).by(t / 200, {
        x: t
      }).delay(1).by(t / 200, {
        x: -t
      }).call(function () {
        if (0 != $2DataManager.default.instance.level) {
          $2UIManager.default.instance.openUI("PrepareCards");
          if (!(2 != $2DataManager.default.instance.level || $2UserDataManager.default.instance.levelGuide)) {
            _this178.node.getChildByName("PauseBtn").active = false, _this178.node.getChildByName("Bomb").active = false, $2UIManager.default.instance.openUI("GuideUI2").emit("nextStep");
          }
          $2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p3") && $2UIManager.default.instance.openUI("MoreGameUI", 999);
        } else {
          _this178.node.getChildByName("Bomb").active = false;
          $2UIManager.default.instance.openUI("GuideUI2").emit("init", 1);
        }
      }).start();
      this.initBallPlantID();
      $2DataManager.default.instance.noCD && $2ADManager.default.instance.isTest && (this.goldNums += 1e4);
      $2kc.default.regMsgReciever($2KDefine.Msg.showNoSunUI, function () {
        _this178.showNoSunUI();
        return false;
      });
    }
  }, {
    key: "onDisable",
    value: function onDisable() {
      cc.kSpeed(1);
      this.is_lbs = false;
      $2kc.default.log("战斗退出");
      $2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().closeNative("nativeIcon");
    }
  }, {
    key: "on_lbs",
    value: function on_lbs() {
      if (this.is_lbs) {
        cc.kSpeed(1);
        this.is_lbs = false;
        this.bs_btn.setPosition(this.bs2.position);
      } else {
        cc.kSpeed(2);
        this.is_lbs = true;
        this.bs_btn.setPosition(this.bs1.position);
      }
    }
  }, {
    key: "showRecorder",
    value: function showRecorder() {
      if ("tt" === $2pvzChannel.pvzChannel.instance().channel) {
        this.recordBt.show(this);
      } else {
        this.recordBt.node.active = false;
      }
    }
  }, {
    key: "showShareVideoWin",
    value: function showShareVideoWin() {
      if ("tt" === $2pvzChannel.pvzChannel.instance().channel) {
        if ($2pvzChannel.pvzChannel.instance().getRecordTime() < 15e3) {
          $2UIManager.default.instance.showToast("录屏失败，录屏时长需要大于15秒");
        } else {
          $2UIManager.default.instance.openUI("SharePanelUI", 40, this.node).getComponent($2SharePanelUI.default).init(0);
        }
      }
    }
  }, {
    key: "showZombie",
    value: function showZombie() {
      var e = $2ZombieMgr.default.instance().waveData.zNum;
      var t = $2ZombieMgr.default.instance().waveData.zombieType;
      for (var _a43 = 0; _a43 < e; _a43++) {
        var _e84 = t[_a43 % t.length];
        var _n46 = $2Common.default.getZombieName(_e84);
        var _i13 = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "PoolNode/" + _n46, cc.Prefab));
        _i13.parent = this.node.getChildByName("ZombieNode");
        _i13.getComponent($2Zombie.default).reset(_e84);
        _i13.getComponent($2Zombie.default).daiji();
      }
    }
  }, {
    key: "createBall",
    value: function createBall() {
      var _this179 = this;
      this.ballPlant++;
      var e = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "Object/plantBall", cc.Prefab));
      e.parent = this.node.getChildByName("ballNode");
      e.getComponent($2Ball.default).init($2MyUtils.MyUtils.getArrRandomValue(_n45.instance.ballPlantID));
      this.canCreateBall = false;
      this.scheduleOnce(function () {
        _this179.canCreateBall = true;
      }, 36);
    }
  }, {
    key: "initBallPlantID",
    value: function initBallPlantID() {
      this.ballPlantID = [];
      for (var _e85 = 0; _e85 < $2DataManager.default.instance.rare5Array.length; _e85++) {
        $2UserDataManager.default.instance.plantLock.includes[this.ballPlantID[_e85]] || $2DataManager.default.instance.selectPlantID.includes[this.ballPlantID[_e85]] || this.ballPlantID.push($2DataManager.default.instance.rare5Array[_e85]);
      }
    }
  }, {
    key: "initPlatform",
    value: function initPlatform() {
      if ($2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0) {
        $2pvzChannel.pvzChannel.instance().showNative(null, cc.v2(5, 150), "nativeIcon");
        if ($2pvzChannel.pvzChannel.instance().getCtrl("p7")) {
          this.video1.active = false, this.video2.active = false, this.video3.active = false, this.video4.active = false;
        }
        $2pvzChannel.pvzChannel.instance().getCtrl("p8") && $2pvzChannel.pvzChannel.instance().pauseAdTimeCount();
      } else {
        "tt" === $2pvzChannel.pvzChannel.instance().channel && this.showRecorder();
      }
    }
  }, {
    key: "play",
    value: function play() {
      var _this180 = this;
      var e;
      this.showPlantDeck();
      $2ZombieMgr.default.instance().play();
      this.node.getChildByName("Gold").active = true;
      this.node.getChildByName("Begin").active = true;
      this.node.getChildByName("ZombieNode").active = false;
      this.lbs_btn.active = true;
      if (20 == $2DataManager.default.instance.level) {
        $2Boss.default.instance.play();
        this.boss.node.x = 720;
        this.boss.setAnimation(0, "ruchang", false);
        this.boss.setCompleteListener(function () {
          _this180.boss.setCompleteListener(null);
          _this180.boss.setAnimation(0, "daiji", true);
        });
        e = this.node.getChildByName("Begin").getComponent(sp.Skeleton).setAnimation(0, "boss", false);
        this.node.getChildByName("Begin").getComponent(sp.Skeleton).setTrackEventListener(e, function (e, t) {
          "boss" == t.data.name && $2AudioManager.default.instance.playEffect("boss");
        });
        this.hpProgress.active = true;
      } else {
        e = this.node.getChildByName("Begin").getComponent(sp.Skeleton).setAnimation(0, "kaishi", false);
        this.node.getChildByName("Begin").getComponent(sp.Skeleton).setTrackEventListener(e, function () {});
      }
      if (0 != $2DataManager.default.instance.level) {
        this.node.getChildByName("PauseBtn").active = true;
        this.node.getChildByName("shovelPanel").active = true;
        this.autoBtn.active = true;
        this.schedule(function () {
          _this180.generateGold();
        }, 15);
        this.schedule(function () {
          _this180.generateSPIcon();
        }, 30);
      }
      this.goldNums += 0;
      this.initPlatform();
    }
  }, {
    key: "pause",
    value: function pause() {
      this.isPause = true;
      $2ZombieMgr.default.instance().pause();
      for (var _e86 = 0; _e86 < 5; _e86++) {
        for (var _t56 = 0; _t56 < 9; _t56++) {
          var _a44 = $2DataManager.default.instance.blockArr[_e86][_t56][1];
          if (_a44) {
            var _e87 = _a44.getComponent($2PlantBase.default);
            _e87 && _e87.pause();
          }
        }
      }
    }
  }, {
    key: "resume",
    value: function resume() {
      this.isPause = false;
      $2ZombieMgr.default.instance().resume();
      for (var _e88 = 0; _e88 < 5; _e88++) {
        for (var _t57 = 0; _t57 < 9; _t57++) {
          var _a45 = $2DataManager.default.instance.blockArr[_e88][_t57][1];
          if (_a45) {
            var _e89 = _a45.getComponent($2PlantBase.default);
            _e89 && _e89.resume();
          }
        }
      }
    }
  }, {
    key: "showFire",
    value: function showFire() {
      $2UserDataManager.default.instance.huangGuaGuide || 2 != $2DataManager.default.instance.level || this.huangGuaGuide();
      this.node.getChildByName("Bomb").getChildByName("Fire").active = true;
    }
  }, {
    key: "huangGuaGuide",
    value: function huangGuaGuide() {
      $2UserDataManager.default.instance.huangGuaGuide = true;
      $2UIManager.default.instance.openUI("GuideUI2").emit("init", 6);
    }
  }, {
    key: "onClickBomb",
    value: function onClickBomb() {
      var _this181 = this;
      if (this.bombNums > 0) {
        this.bombNums--;
        0 == this.bombNums && ($2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p7") || (this.node.getChildByName("Bomb").getChildByName("video").active = true));
        this.shootBomb();
      } else {
        var _e90 = function _e90() {
          _this181.shootBomb();
        };
        var _t58 = function _t58() {};
        var _a46 = function _a46() {};
        $2pvzChannel.pvzChannel.instance().showVideo({
          sucCall: _e90,
          failCall: _t58,
          endCall: _a46
        });
      }
    }
  }, {
    key: "shootBomb",
    value: function shootBomb() {
      var _this182 = this;
      this.node.getChildByName("Bomb").getComponent(cc.Button).interactable = false;
      var e = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "Object/Bomb"));
      e.parent = this.node;
      var t = e.getComponent(sp.Skeleton).setAnimation(0, "baozha", false);
      e.getComponent(sp.Skeleton).setTrackEventListener(t, function (e, t) {
        if ("baozha" == t.data.name) {
          $2AudioManager.default.instance.playEffect("HuangGuaEff");
          var _e91 = babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values()).length;
          for (var _t59 = 0; _t59 < _e91; _t59++) {
            babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[_t59] && babel_toConsumableArray($2ZombieMgr.default.instance().zombieSet.values())[_t59].hurt(2e3 * $2UserDataManager.default.instance.chapter);
          }
        }
      });
      e.getComponent(sp.Skeleton).setCompleteListener(function () {
        _this182.node.getChildByName("Bomb").getComponent(cc.Button).interactable = true;
        e.destroy();
        2 == $2DataManager.default.instance.level && $2UIManager.default.instance.uiList.GuideUI2 && $2UIManager.default.instance.uiList.GuideUI2.emit("nextStep");
      });
    }
  }, {
    key: "onClickRecord",
    value: function onClickRecord() {
      if (this.isRecord) {
        this.isRecord = false;
        this.endTime = new Date().getTime();
        if (this.endTime - this.startTime >= 3e3) {
          $2ADManager.default.instance.recorderStop();
        } else {
          $2UIManager.default.instance.showToast("录屏时长小于3秒");
        }
        this.node.getChildByName("Record").getComponentInChildren(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ShareUI/play", cc.SpriteFrame);
        this.node.getChildByName("Record").children[2].active = false;
        this.node.getChildByName("Record").getComponentInChildren(cc.Label).string = "开始录屏";
      } else {
        this.isRecord = true;
        $2ADManager.default.instance.recorderStart();
        this.startTime = new Date().getTime();
        this.node.getChildByName("Record").getComponentInChildren(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ShareUI/pause", cc.SpriteFrame);
        this.node.getChildByName("Record").getComponentInChildren(cc.Label).string = "停止录屏";
        this.node.getChildByName("Record").children[2].active = true;
      }
    }
  }, {
    key: "createTombstone",
    value: function createTombstone(e) {
      for (var _t60 = 0; _t60 < e.length; _t60++) {
        var _a47 = $2PoolManager.default.instance.getPoolNode("Tombstone");
        _a47.parent = this.groudNode;
        var _n47 = Math.floor((e[_t60] - 1) / 9);
        var _i14 = (e[_t60] - 1) % 9;
        _a47.getComponent($2TombStone.default).init(_n47, _i14);
        _a47.setPosition($2DataManager.default.instance.blockArr[_n47][_i14][0]);
        $2DataManager.default.instance.blockArr[_n47][_i14][1] = _a47;
      }
    }
  }, {
    key: "showProgress",
    value: function showProgress(e) {
      this.gameProgress.getChildByName("Head").zIndex = 33;
      var t = [];
      for (var _a48 = 0; _a48 < e.length; _a48++) {
        this.allTime += e[_a48];
        t.push(this.allTime);
      }
      for (var _a49 = 1; _a49 < t.length; _a49++) {
        var _e92 = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "Object/Chess"));
        _e92.parent = this.gameProgress;
        _e92.x = -(this.gameProgress.width - 25) * t[_a49 - 1] / this.allTime;
      }
      this.gameProgress.active = true;
    }
  }, {
    key: "showBossHp",
    value: function showBossHp() {
      if ($2Boss.default.instance.hp > 0) {
        this.hpProgress.getComponent(cc.ProgressBar).progress = $2Boss.default.instance.hp / $2Boss.default.instance.allHp + .02;
      } else {
        this.hpProgress.getComponent(cc.ProgressBar).progress = 0;
      }
    }
  }, {
    key: "goldNums",
    get() {
      return this._goldNums;
    },
    set(e) {
      var _this183 = this;
      this._goldNums = e;
      this.goldNumLabel.string = e + "";
      this.cardNodeMap.forEach(function (e, t) {
        if ($2PlantMgr.default.instance().getPlant(t).cost[$2UserDataManager.default.instance.getPlantLevel(t) - 1][1] > _this183.goldNums) {
          e.getComponent($2Card.default).costMask.active = true;
        } else {
          e.getComponent($2Card.default).costMask.active = false;
        }
      });
    }
  }, {
    key: "showPlantDeck",
    value: function showPlantDeck() {
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
      this.shovel.on(cc.Node.EventType.TOUCH_START, this.onShovelStart, this);
      this.shovel.on(cc.Node.EventType.TOUCH_MOVE, this.onShovelMove, this);
      this.shovel.on(cc.Node.EventType.TOUCH_END, this.onShovelEnd, this);
      this.shovel.on(cc.Node.EventType.TOUCH_CANCEL, this.onShovelEnd, this);
      this.groudNode.getChildByName("Gird").on(cc.Node.EventType.TOUCH_END, this.onClickBg, this);
      ($2UserDataManager.default.instance.huangGuaGuide || 2 != $2DataManager.default.instance.level && 0 != $2DataManager.default.instance.level) && this.showBtn();
      $2TaSdk.default.instance.AdsExposure($2TaSdk.VideoIndex.autoPick);
      $2TaSdk.default.instance.AdsExposure($2TaSdk.VideoIndex.huangGua);
      this.showDeck(e);
    }
  }, {
    key: "showBtn",
    value: function showBtn() {
      $2UserDataManager.default.instance.noCDGuide || $2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p7") || (this.node.getChildByName("CDBtn").getChildByName("video").active = false);
      $2UserDataManager.default.instance.extraGoldGuide || $2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p7") || (this.node.getChildByName("GoldBtn").getChildByName("video").active = false);
      if ($2pvzChannel.pvzChannel.instance().channel.indexOf("wx") < 0) {
        this.node.getChildByName("GoldBtn").active = true;
        this.node.getChildByName("CDBtn").active = true;
        this.showBomb();
      }
    }
  }, {
    key: "showBomb",
    value: function showBomb() {
      this.node.getChildByName("Bomb").active = true;
      if (this.bombNums > 0) {
        $2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p7") || (this.node.getChildByName("Bomb").getChildByName("video").active = false);
      } else {
        $2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p7") || (this.node.getChildByName("Bomb").getChildByName("video").active = true);
      }
    }
  }, {
    key: "showDeck",
    value: function showDeck() {
      var _this184 = this;
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
      var t = $2DataManager.default.instance.selectPlantID;
      $2kc.default.uiLayout({
        resPath: {
          pic: "scene_stage/img/prop/",
          prefab: "scene_stage/"
        },
        layout: [{
          id: "plant",
          type: "gird",
          itemPadding: [0, 7],
          colCount: 1,
          itemPrefab: "PlantPrefab/plant_1"
        }, {
          id: "card",
          type: "gird",
          itemPadding: [0, 7],
          colCount: 1,
          itemPrefab: "card/card_1"
        }]
      }, [this.plantPanel, this.cardPanel], function (e, t, a, _n48) {
        if ("card" === _n48.id) {
          var _t61 = e.getComponent($2Card.default);
          _t61.name = a;
          _t61.init(a);
          return void _this184.cardNodeMap.set(a, e);
        }
        e.opacity = 0;
        $2Common.default.addPlantComponent(a, e);
        var i = e.getComponent($2PlantBase.default);
        i.reset(a);
        i.node.on(cc.Node.EventType.TOUCH_START, _this184.onCardPick, _this184);
        i.node.on(cc.Node.EventType.TOUCH_MOVE, _this184.onCardMoving, _this184);
        i.node.on(cc.Node.EventType.TOUCH_END, _this184.onCardRelease, _this184);
        i.node.on(cc.Node.EventType.TOUCH_CANCEL, _this184.onCardRelease, _this184);
        _this184.plantNodeMap.set(a, e);
      }, [t, t], this, e);
    }
  }, {
    key: "onCardPick",
    value: function onCardPick(e) {
      if (this.isPause) {
        return;
      }
      var t = e.currentTarget;
      this.pickStartPo = t.getPosition();
      var a = t.getComponent($2PlantBase.default);
      var _n49 = a.cost;
      if (this.goldNums >= _n49) {
        this.selectCardID = a.id;
        0 != this.lastCardID && (this.cardNodeMap.get(this.lastCardID).getChildByName("HighLight").active = false);
        this.cardNodeMap.get(this.selectCardID).getChildByName("HighLight").active = true;
        this.lastCardID = this.selectCardID;
        a.canMove = true;
        a.inUse = false;
        a.node.opacity = 255;
        var _e93 = this.cardNodeMap.get(a.id);
        _e93.color = cc.color(100, 100, 100);
        t.parent = this.groudNode;
        t.setPosition(cc.v2(t.x, t.y + 30).addSelf(this.plantPanel.getPosition()));
        t.getComponentInChildren(sp.Skeleton).setAnimation(0, "daiji", true);
        this.cardSelectShadow = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "card/card_2"));
        this.cardSelectShadow.getChildByName("plant").getComponent(cc.Sprite).spriteFrame = _e93.getChildByName("icon").getComponent(cc.Sprite).spriteFrame;
        this.cardSelectShadow.parent = this.groudNode;
        this.cardSelectShadow.opacity = 0;
      }
    }
  }, {
    key: "onClickCDBtn",
    value: function onClickCDBtn() {
      var _this185 = this;
      if ($2DataManager.default.instance.noCD) {
        return;
      }
      var e = function e() {
        if (!$2UserDataManager.default.instance.noCDGuide) {
          $2UserDataManager.default.instance.noCDGuide = true;
          $2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p7") || (_this185.node.getChildByName("CDBtn").getChildByName("video").active = true);
          _this185.node.getChildByName("CDBtn").getChildByName("Tip").active = true;
          _this185.scheduleOnce(function () {
            _this185.node.getChildByName("CDBtn").getChildByName("Tip").active = false;
          }, 3);
        }
        _this185.noCDTime = 10;
        _this185.node.getChildByName("CDBtn").getChildByName("Time").active = true;
        _this185.schedule(function () {
          _this185.noCDTime--;
          _this185.node.getChildByName("CDBtn").getChildByName("Time").getComponent(cc.Label).string = _this185.noCDTime + "";
        }, 1, 10);
        $2DataManager.default.instance.noCD = true;
        _this185.node.getChildByName("CDBtn").getChildByName("Pro").getComponent(cc.Sprite).fillRange = 1;
        cc.tween(_this185.node.getChildByName("CDBtn").getChildByName("Pro").getComponent(cc.Sprite)).to(10, {
          fillRange: 0
        }).call(function () {
          _this185.node.getChildByName("CDBtn").getChildByName("Time").active = false;
          $2DataManager.default.instance.noCD = false;
          $2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p7") || (_this185.node.getChildByName("CDBtn").getChildByName("video").active = true);
        }).start();
        $2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p7") || (_this185.node.getChildByName("CDBtn").getChildByName("video").active = false);
      };
      var t = function t() {};
      var a = function a() {};
      if ($2UserDataManager.default.instance.noCDGuide) {
        if ($2pvzChannel.pvzChannel.bt4_firstFree) {
          e();
          return void ($2pvzChannel.pvzChannel.bt4_firstFree = false);
        }
        $2pvzChannel.pvzChannel.instance().showVideo({
          sucCall: e,
          failCall: t,
          endCall: a
        });
      } else {
        $2kc.default.log("首次免费给noCDGuide");
        e();
      }
    }
  }, {
    key: "onClickAddGold",
    value: function onClickAddGold() {
      var _this186 = this;
      $2pvzChannel.pvzChannel.instance().showVideo({
        sucCall() {
          _this186.goldNums += 1e3;
          if (!($2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 || $2UserDataManager.default.instance.extraGoldGuide)) {
            $2UserDataManager.default.instance.extraGoldGuide = true;
            $2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p7") || (_this186.node.getChildByName("GoldBtn").getChildByName("video").active = true);
            _this186.node.getChildByName("GoldBtn").getChildByName("Tip").active = true;
            _this186.scheduleOnce(function () {
              _this186.node.getChildByName("GoldBtn").getChildByName("Tip").active = false;
            }, 3);
          }
        },
        failCall() {},
        endCall() {}
      });
    }
  }, {
    key: "generateGold",
    value: function generateGold() {
      if (this.isPause) {
        return;
      }
      var e = $2MyUtils.MyUtils.getRandomInt(-450, 400);
      var t = $2MyUtils.MyUtils.getRandomInt(1, 5);
      $2GoldManager.default.instance.getItem(e, 470, t, 50).parent = this.sunParent;
    }
  }, {
    key: "generateSPIcon",
    value: function generateSPIcon() {
      if (this.isPause) {
        return;
      }
      var e = $2MyUtils.MyUtils.getRandomInt(-450, 400);
      var t = $2MyUtils.MyUtils.getRandomInt(1, 5);
      $2kc.default.log("生成飘屏icon", e, t, this.spIconType);
      cc.instantiate(this.spIcon).getComponent($2SpIcon.default).show(e, 470, t, this, this.spIconType);
      if (0 === this.spIconType) {
        this.spIconType = 1;
      } else {
        this.spIconType = 0;
      }
    }
  }, {
    key: "onCardMoving",
    value: function onCardMoving(e) {
      if (this.isPause) {
        return;
      }
      var t = e.currentTarget;
      if (!t.getComponent($2PlantBase.default).canMove) {
        return;
      }
      var a = cc.v2(t.x + e.getDeltaX(), t.y + e.getDeltaY());
      t.setPosition(a);
      var _n50 = this.checkMovedPlantPos(a);
      if (_n50) {
        this.cardSelectShadow.setPosition(_n50[0].x, _n50[0].y + 30);
        this.cardSelectShadow.opacity = 150;
        this.cardSelectShadow.getChildByName("col").x = 80.5 * -_n50[2];
        this.cardSelectShadow.getChildByName("row").y = 93 * -_n50[1];
      }
    }
  }, {
    key: "onCardRelease",
    value: function onCardRelease(e) {
      if (this.isPause) {
        return;
      }
      var t = e.currentTarget;
      var a = t.getComponent($2PlantBase.default);
      if (!a.canMove) {
        return;
      }
      var _n51 = cc.v2(e.currentTarget.x, e.currentTarget.y);
      a.canMove = false;
      t.opacity = 0;
      t.parent = this.plantPanel;
      t.setPosition(this.pickStartPo);
      this.cardSelectShadow.destroy();
      var i = this.checkMovedPlantPos(_n51);
      if (!i) {
        return void (this.cardNodeMap.get(a.id).color = cc.Color.WHITE);
      }
      $2UserDataManager.default.instance.taskInfo[2].progress++;
      this.cardNodeMap.get(this.selectCardID).getChildByName("HighLight").active = false;
      this.selectCardID = 0;
      this.lastCardID = 0;
      var l = a.cost;
      this.goldNums -= l;
      this.cardNodeMap.get(a.id).getComponent($2Card.default).showCD();
      if ($2DataManager.default.instance.multi_plants) {
        var _e94 = i[2];
        for (var _n56 = 0; _n56 < 5; _n56++) {
          if ($2DataManager.default.instance.blockArr[_n56][_e94][1]) {
            continue;
          }
          var _s11 = $2DataManager.default.instance.blockArr[_n56][_e94][0];
          var _l3 = cc.instantiate(t);
          _l3.parent = this.groudNode;
          _l3.opacity = 255;
          _l3.setPosition(_s11);
          _l3.getComponent($2PlantBase.default).reset(a.id, false);
          _l3.getComponent($2PlantBase.default).play(_n56, i[2]);
          _l3.getChildByName("PlantEffect").active = true;
          $2DataManager.default.instance.blockArr[_n56][i[2]][1] = _l3;
        }
      } else {
        var _e95 = cc.instantiate(t);
        _e95.parent = this.groudNode;
        _e95.opacity = 255;
        _e95.setPosition(i[0].x, i[0].y - 10);
        _e95.getComponent($2PlantBase.default).reset(a.id, true);
        _e95.getComponent($2PlantBase.default).play(i[1], i[2]);
        _e95.getChildByName("PlantEffect").active = true;
        $2DataManager.default.instance.blockArr[i[1]][i[2]][1] = _e95;
      }
      this.cardNodeMap.get(a.id).color = cc.Color.WHITE;
      $2AudioManager.default.instance.playEffect($2KDefine.AudioName.PutPlantEff);
    }
  }, {
    key: "showBombUI",
    value: function showBombUI() {
      // cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "UIPrefab/AdBombUI", cc.Prefab)).getComponent($2AdBombUI.default).show($2UIManager.default.instance.uiRoot);
    }
  }, {
    key: "showNoSunUI",
    value: function showNoSunUI() {
      cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "UIPrefab/NoSunUI", cc.Prefab)).getComponent($2NoSunUI.default).show($2UIManager.default.instance.uiRoot);
    }
  }, {
    key: "showReviveUI",
    value: function showReviveUI(e, t) {
      // cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "UIPrefab/AdReviveUI", cc.Prefab)).getComponent($2AdReviveUI.default).show(e, $2UIManager.default.instance.uiRoot, t);
    }
  }, {
    key: "revivePlant",
    value: function revivePlant(e, t, a, i) {
      var s = _n45.instance.plantNodeMap.get(e);
      if (!s) {
        return;
      }
      var l = cc.instantiate(s);
      l.parent = this.groudNode;
      l.opacity = 255;
      l.setPosition(t);
      l.getComponent($2PlantBase.default).reset(e, true);
      l.getComponent($2PlantBase.default).play(a, i);
      l.getChildByName("PlantEffect").active = true;
      $2DataManager.default.instance.blockArr[a][i][1] = l;
    }
  }, {
    key: "onClickBg",
    value: function onClickBg(e) {
      if (0 != this.selectCardID) {
        var _t62 = e.getLocation();
        var _a50 = this.groudNode.convertToNodeSpaceAR(_t62);
        var _n53 = this.checkMovedPlantPos(_a50);
        if (_n53) {
          var _e96 = this.plantNodeMap.get(this.selectCardID);
          this.cardNodeMap.get(this.selectCardID).getChildByName("HighLight").active = false;
          this.selectCardID = 0;
          this.lastCardID = 0;
          var _t63 = _e96.getComponent($2PlantBase.default).cost;
          this.goldNums -= _t63;
          this.cardNodeMap.get(_e96.getComponent($2PlantBase.default).id).getComponent($2Card.default).showCD();
          var _a51 = cc.instantiate(_e96);
          _a51.parent = this.groudNode;
          _a51.opacity = 255;
          _a51.setPosition(_n53[0]);
          _a51.getComponent($2PlantBase.default).reset(_e96.getComponent($2PlantBase.default).id, true);
          _a51.getComponent($2PlantBase.default).play(_n53[1], _n53[2]);
          _a51.getChildByName("PlantEffect").active = true;
          $2DataManager.default.instance.blockArr[_n53[1]][_n53[2]][1] = _a51;
        }
      }
    }
  }, {
    key: "onClickAutoBtn",
    value: function onClickAutoBtn() {
      var _this187 = this;
      $2pvzChannel.pvzChannel.instance().showVideo({
        sucCall() {
          _this187.autoBtn.active = false;
          _this187.autoPick = true;
          for (var _e97 = 0; _e97 < _this187.sunParent.childrenCount; _e97++) {
            var _t64 = _this187.sunParent.children[_e97].getComponent($2Gold.default);
            _t64 && _t64.onClickGold();
          }
        },
        failCall() {},
        endCall() {}
      });
    }
  }, {
    key: "onClickPause",
    value: function onClickPause() {
      $2UIManager.default.instance.openUI("PauseUI", 30);
    }
  }, {
    key: "lose",
    value: function lose() {
      if (20 == $2DataManager.default.instance.level) {
        $2TaSdk.default.instance.postEvent("level", {
          level: 20,
          is_Win: 0
        });
        $2Hts.default.instance.eventReport("第" + $2UserDataManager.default.instance.chapter + "周目第" + $2DataManager.default.instance.bossLevel + "级Boss关失败");
      } else {
        $2Hts.default.instance.eventReport("第" + $2UserDataManager.default.instance.chapter + "周目第" + $2DataManager.default.instance.level + "关失败");
        $2TaSdk.default.instance.postEvent("level", {
          level: $2DataManager.default.instance.level,
          is_Win: 0
        });
      }
      $2UIManager.default.instance.closeUI("MainUI");
      $2UIManager.default.instance.openUI("FailUI");
    }
  }, {
    key: "win",
    value: function win() {
      if (20 == $2DataManager.default.instance.level) {
        $2TaSdk.default.instance.postEvent("level", {
          level: 20,
          is_Win: 1
        });
        $2Hts.default.instance.eventReport("第" + $2UserDataManager.default.instance.chapter + "周目第" + $2DataManager.default.instance.bossLevel + "级Boss关成功");
        $2UserDataManager.default.instance.taskInfo[6].progress++;
      } else {
        $2Hts.default.instance.eventReport("第" + $2UserDataManager.default.instance.chapter + "周目第" + $2DataManager.default.instance.level + "关成功");
        $2TaSdk.default.instance.postEvent("level", {
          level: $2DataManager.default.instance.level,
          is_Win: 1
        });
        $2UserDataManager.default.instance.taskInfo[4].progress++;
      }
      this.scheduleOnce(function () {
        $2UIManager.default.instance.closeUI("MainUI");
        $2UIManager.default.instance.openUI("SuccessUI");
      }, 3);
    }
  }, {
    key: "checkMovedPlantPos",
    value: function checkMovedPlantPos(e) {
      if (e.x > this.groudXMax || e.x < this.groudXMin || e.y > this.groudYMax || e.y < this.groudYMin) {
        return null;
      }
      var t = e.sub($2DataManager.default.instance.groudStartPo);
      var a = Math.floor(t.x / $2DataManager.default.instance.blockWidth);
      var _n54 = Math.floor(t.y / $2DataManager.default.instance.blockHeight);
      if ($2DataManager.default.instance.blockArr[_n54][a][1]) {
        return null;
      } else {
        return [$2DataManager.default.instance.blockArr[_n54][a][0], _n54, a];
      }
    }
  }, {
    key: "getShovelShadowPos",
    value: function getShovelShadowPos(e) {
      if (e.x >= this.groudXMax || e.x <= this.groudXMin || e.y >= this.groudYMax || e.y <= this.groudYMin) {
        return null;
      }
      var t = e.sub($2DataManager.default.instance.groudStartPo);
      var a = Math.floor(t.x / $2DataManager.default.instance.blockWidth);
      var _n55 = Math.floor(t.y / $2DataManager.default.instance.blockHeight);
      return [$2DataManager.default.instance.blockArr[_n55][a][0], _n55, a];
    }
  }, {
    key: "onShovelStart",
    value: function onShovelStart(e) {
      e.currentTarget.parent.getChildByName("shovelBtn").opacity = 140;
      e.currentTarget.opacity = 255;
    }
  }, {
    key: "onShovelMove",
    value: function onShovelMove(e) {
      e.currentTarget.setPosition(e.currentTarget.x + e.getDeltaX() / this.node.scale, e.currentTarget.y + e.getDeltaY() / this.node.scale);
      var t = this.getShovelShadowPos(e.currentTarget.getPosition());
      if (t) {
        this.shovelShadow.setPosition(t[0].x, t[0].y + 30);
        this.shovelShadow.opacity = 140;
        var _e98 = t[1];
        var _a52 = t[2];
        this.shovelShadow.getChildByName("col").x = 80.5 * -_a52;
        this.shovelShadow.getChildByName("row").y = 93 * -_e98;
        if ($2DataManager.default.instance.blockArr[_e98][_a52][1] && $2DataManager.default.instance.blockArr[_e98][_a52][1].getComponent($2PlantBase.default)) {
          this.tempPlant && (this.tempPlant.opacity = 255);
          this.tempPlant = $2DataManager.default.instance.blockArr[_e98][_a52][1];
          this.tempPlant.opacity = 140;
        } else if (this.tempPlant) {
          this.tempPlant.opacity = 255, this.tempPlant = null;
        }
      }
    }
  }, {
    key: "onShovelEnd",
    value: function onShovelEnd(e) {
      var t = this.getShovelShadowPos(e.currentTarget.getPosition());
      if (t) {
        var _e99 = t[1];
        var _a53 = t[2];
        if ($2DataManager.default.instance.blockArr[_e99][_a53][1] && $2DataManager.default.instance.blockArr[_e99][_a53][1].getComponent($2PlantBase.default)) {
          $2DataManager.default.instance.blockArr[_e99][_a53][1].destroy();
          this.delPlantInBlckArr(_e99, _a53);
          $2AudioManager.default.instance.playEffect($2KDefine.AudioName.ShovelEff);
        }
      } else if (this.tempPlant) {
        this.tempPlant.opacity = 255;
        this.tempPlant = null;
      }
      e.currentTarget.parent.getChildByName("shovelBtn").opacity = 255;
      e.currentTarget.opacity = 0;
      e.currentTarget.x = 500;
      e.currentTarget.y = -300;
      this.shovelShadow.opacity = 0;
    }
  }, {
    key: "delPlantInBlckArr",
    value: function delPlantInBlckArr(e, t) {
      $2DataManager.default.instance.blockArr[e][t][1] = null;
    }
  }, {
    key: "update",
    value: function update(e) {
      this.isPause || this.isPlay && !this.isGuide && (this.nowTime += e, this.gameProgress.getComponent(cc.ProgressBar).progress = this.nowTime / this.allTime, this.gameProgress.getChildByName("Head").x = -this.gameProgress.getComponent(cc.ProgressBar).progress * this.gameProgress.width);
    }
  }, {
    key: "onDestroy",
    value: function onDestroy() {
      $2ADManager.default.instance.hideBanner();
    }
  }], [{
    key: "instance",
    get() {
      return this._instance;
    }
  }]);
  return n;
}(cc.Component);
def_SceneStage._instance = null;
cc__decorate([ccp_property(cc.Prefab)], def_SceneStage.prototype, "spIcon", undefined);
cc__decorate([ccp_property(cc.Node)], def_SceneStage.prototype, "video1", undefined);
cc__decorate([ccp_property(cc.Node)], def_SceneStage.prototype, "video2", undefined);
cc__decorate([ccp_property(cc.Node)], def_SceneStage.prototype, "video3", undefined);
cc__decorate([ccp_property(cc.Node)], def_SceneStage.prototype, "video4", undefined);
cc__decorate([ccp_property(cc.Node)], def_SceneStage.prototype, "groudNode", undefined);
cc__decorate([ccp_property($2pvzRecordVideoBt.default)], def_SceneStage.prototype, "recordBt", undefined);
cc__decorate([ccp_property(cc.Node)], def_SceneStage.prototype, "cardPanel", undefined);
cc__decorate([ccp_property(cc.Node)], def_SceneStage.prototype, "plantPanel", undefined);
cc__decorate([ccp_property(cc.Label)], def_SceneStage.prototype, "goldNumLabel", undefined);
cc__decorate([ccp_property(cc.Node)], def_SceneStage.prototype, "shovel", undefined);
cc__decorate([ccp_property(cc.Node)], def_SceneStage.prototype, "gameProgress", undefined);
cc__decorate([ccp_property(cc.Node)], def_SceneStage.prototype, "autoBtn", undefined);
cc__decorate([ccp_property(cc.Node)], def_SceneStage.prototype, "sunParent", undefined);
cc__decorate([ccp_property(sp.Skeleton)], def_SceneStage.prototype, "boss", undefined);
def_SceneStage = _n45 = cc__decorate([ccp_ccclass], def_SceneStage);
exports.default = def_SceneStage;